import requests

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", 
    "Accept-Encoding": "gzip, deflate, br, zstd", 
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", 
    "Host": "cn.baozimhcn.com", 
    "Priority": "u=0, i", 
    "Sec-Ch-Ua": "\"Chromium\";v=\"136\", \"Microsoft Edge\";v=\"136\", \"Not.A/Brand\";v=\"99\"", 
    "Sec-Ch-Ua-Mobile": "?0", 
    "Sec-Ch-Ua-Platform": "\"Windows\"", 
    "Sec-Fetch-Dest": "document", 
    "Sec-Fetch-Mode": "navigate", 
    "Sec-Fetch-Site": "none", 
    "Sec-Fetch-User": "?1", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0"
}

class Req:
    def __init__(self, url, method='get', headers=None, timeout=1000):
        self.url = url
        self.method = method
        self.headers = headers
        self.timeout = timeout

    def send(self):
        try:
            response = requests.request(self.method, self.url, headers=self.headers, timeout=self.timeout, allow_redirects=False)
            response.raise_for_status()  # Raise an error for bad responses (4xx and 5xx)
            #print(response.headers)
            if response.headers.get("Location")!=None:
                return ""
            return response.content
        except requests.RequestException as e:
            print(f"Request failed: {e}")
            return None